'use strict';

/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = appInfo => {
    /**
     * built-in config
     * @type {Egg.EggAppConfig}
     **/
    const config = exports = {};

    // use for cookie sign key, should change to your own and keep security
    config.keys = appInfo.name + '_1582794763953_5810';

    // add your middleware config here
    config.middleware = ['jwtErr'];

    // add your user config here
    const userConfig = {
        // myAppName: 'egg',
    };
    config.security = {
        csrf: {
            enable: false,
        },
    };
    config.mysql = {
        client: {
            // host
            // host: '39.96.25.50',
            host: '127.0.0.1',
            // 端口号
            port: '3306',
            // 用户名
            user: 'root',
            // 密码
            password: '123456',
            // 数据库名
            database: 'forum',
        },
        // 是否加载到 app 上，默认开启
        app: true,
        // 是否加载到 agent 上，默认关闭
        agent: false,
    };
    config.jwt = {
        secret: "123456" //自定义 token 的加密条件字符串
    };
    config.cors = {
        origin: '*',
        allowMethods: 'GET,POST,PUT,DELETE,PATCH'
    };
    config.validate = {
        resolveError(ctx, errors) {
            if (errors.length) {
                ctx.type = 'json';
                ctx.status = 400;
                ctx.body = {
                    code: -1,
                    error: errors,
                    message: '参数错误',
                };
            }
        }
    };

    return {
        ...config,
        ...userConfig,
    };
};